package 剑指offer.替换空格_2;

import java.util.Scanner;

/**
 * 请实现一个函数，将一个字符串中的每个空格替换成“%20”。
 * 例如，当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
 * @author xuliyun
 * @summary
 */
public class Solution {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		StringBuffer sb = new StringBuffer(in.nextLine());
		System.out.println(replaceSpace(sb));
	}
	
	public static String replaceSpace(StringBuffer sb){
		String str = sb.toString();
		StringBuffer res = new StringBuffer();
		char[] dataStr = str.toCharArray();
		for(int i = 0; i < sb.length(); i++){
			if(dataStr[i] == ' ') res.append("%20");
			else res.append(dataStr[i]);
		}
		return res.toString();
	}
}
